/*
 * Copyright (c) 2013.
 * 游戏服务器核心代码编写人陈磊拥有使用权
 * 联系方式：E-mail:13638363871@163.com ;qq:502959937
 * 个人博客主页：http://my.oschina.net/chenleijava
 */

package com.dc.gameserver.serverCore.service.battle.coreBattleLogic.sameCardType;

import com.dc.gameserver.exceptions.logicException;
import com.dc.gameserver.hardCode.CardType;
import com.dc.gameserver.serverCore.service.battle.GameFormula;
import com.dc.gameserver.serverCore.service.battle.coreBattleLogic.AbstractSameLogic;
import com.dc.gameserver.serverCore.service.battle.coreBattleLogic.ISoul;
import com.dc.gameserver.serverCore.service.cardModule.CardBox;
import com.dc.gameserver.serverCore.service.cardModule.CardBoxManager;
import com.dc.gameserver.serverCore.service.character.GameCharacter;
import com.dc.gameserver.serverCore.service.character.Monster;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

/**
 * @author 石头哥哥
 *         Date: 13-11-1</br>
 *         Time: 上午9:58</br>
 *         Package: Server.ServerCore.Service.fightProcess.sameCardType</br>
 *         注解：玩家都出 神识 1  逻辑处理
 *
 *         都出神识牌逻辑
 */
@Service
public class soulLogic extends AbstractSameLogic {

    private static final Logger LOGGER= LoggerFactory.getLogger(soulLogic.class);
    /**
     * 通过spring注解方式初始化处理logic的实例化引用
     */
    @Override
    public void PostConstruct() {
        LOGICS[CardType.SOUL_TYPE.getType()]=this;
    }

    /**
     * logic 处理
     * 双方同时出神识牌时，先判定@先手的神识牌。
     * 神识对气血和法力没有影响，只影响对手的眩晕状态；
     * @param p1 玩家1
     * @param p2 玩家2
     */
    @Override
    public void logicHandle(GameCharacter p1,GameCharacter p2){
         //先手的神识先生效
         if (p1.isFirstHand()){
            //p1 is first
             notifyPlayerGetCardFirst(p1);
         }else {
             //p2 is first
             notifyPlayerGetCardFirst(p2);
         }
    }

    /**
     *
     * 所有玩家都出神识
     * 通知玩家（先手玩家）抽取神识判定牌
     * @param gameCharacter  PVE PVP,都将会通知先手先出牌，PVE 先手默认都是player
     */
    public  void notifyPlayerGetCardFirst(GameCharacter gameCharacter){

        // gameCharacter is player ,  gameCharacter player must be Monster
        if (gameCharacter instanceof Monster){
            throw new logicException("gameCharacter is player , no matter what PVE OR PVP  ,please check logic!");
        }
        CardBox cardBox= CardBoxManager.getCardBoxByID(gameCharacter.getCardBoxID());
        GameCharacter otherPlayer=cardBox.getOtherPlayer(gameCharacter);
        //PVP ,PVE ,都将是   gameCharacter神识先生效判断
        LOGGER.debug("角色都出神牌....逻辑处理："+ gameCharacter);
        int soulType=GameFormula.getSoulSkillType(gameCharacter.getOutCardsList().size());
        LOGGER.debug("角色都出神牌....神识技能类型："+ soulType+">> 0.眩晕 1.以伤换伤 2.秒杀");
        boolean status=ISoul.SOULS[soulType].SoulHandle(gameCharacter, otherPlayer);

        //1.对手眩晕，2.对手秒杀或则被干掉；
        if (status&&otherPlayer.getCurrentShield()==0||status&&otherPlayer.getDizzinessTimes()!=0){
            return;
        }

        //other player 没有眩晕 没有被干掉
        soulType=GameFormula.getSoulSkillType(otherPlayer.getOutCardsList().size());
        status=ISoul.SOULS[soulType].SoulHandle(otherPlayer, gameCharacter);
        LOGGER.debug("角色都出神牌....神识技能类型："+ status+">>soulType>>"+soulType+">> 0.眩晕 1.以伤换伤 2.秒杀");

        if (status&&gameCharacter.getDizzinessTimes()!=0)return;

        if (!status&&gameCharacter.getDizzinessTimes()==0||gameCharacter.getCurrentShield()!=0){
            cardBox.flushBloodAndMagic();
            cardBox.resetRoundResource();
        }

    }
}
